
import java.io.*;

public class writeText {

    int count = 0;

    public void writeToFile(String s) {

        try {

            //Ghi file
            FileOutputStream fos = new FileOutputStream("Example.xml", true);
            PrintWriter pw = new PrintWriter(fos);

            count++;
            pw.println("<record RecId=" + "\"" + count + "\"" + ">");
            pw.println("<Infomation>" + s + "</Infomation>");
            pw.println("</record>");
            pw.close();

        } catch (FileNotFoundException e) {
            System.out.println(e.getMessage());
        } catch (IOException e) {
            System.out.println(e.getMessage());
        }

    }

    public static void main(String[] args) {

        String s = "abc";
        writeText w = new writeText();
        w.writeToFile(s);
    }
}
